package com.ccnu.JobHub.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ccnu.JobHub.mapper.PostMapper;
import com.ccnu.JobHub.model.database.Post;
import com.ccnu.JobHub.service.IPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class PostService extends ServiceImpl<PostMapper, Post> implements IPostService {
    @Autowired
    private PostMapper postMapper;

    @Override
    public List<Map<String ,Object>> getPostCountByDateRange(String startDate, String now) {
        QueryWrapper<Post> postQueryWrapper = new QueryWrapper<Post>()
                .select("Date(created_at) as post_date","count(*) as amount")
                .between("created_at",startDate,now)
                .groupBy("post_date");

        return postMapper.selectMaps(postQueryWrapper);
    }
}
